﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Private.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Utility" %>
<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<asp:Content ID="Content2" ContentPlaceHolderID="TitleHolder" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
    <script type="text/javascript">
        function ShowOrHide_PostingHotNews(status, proId) {
            if (status == "show") {
                $(".private_info_product").show();
                $('#UpTinHotId').val(proId);
            }
            else if (status == "hide") {
                $(".private_info_product").hide();
            }
            return false;
        }
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">
    <% var hMem = (MemberHelper)ViewData["hMem"]; %>
    <!-- Danh mục sản phẩm -->
    <div class="private_share_post">
        <div class="private_share_post_top">
            <div class="private_sharepost_menu">
                <ul>
                    <li><a href="#" class="menu_select">Danh mục sản phẩm</a></li>
                    <li><a href="#">Sản phẩm yêu thích</a></li>
                </ul>
            </div>
            <% if (Session["MemId"] != null)
               {
                   //String[] right = ((String)Session["Rights"]).Split(',');
                   //if(right.Contains("1"))
                   if (hMem.Member.MemId == (int)Session["MemId"])
                   {%>
            <div class="private_write_right">
                <div class="private_bt_newspost">
                    <%--<a href="<%= Url.Action("Index","Home", new { uid = ViewData["MemId"], isEditMode = true}) %>">--%>
                    <a href="<%=Url.RouteUrl("PrivateDetailHomeRoute", new { uid = ViewData["MemId"], isEditMode = true }) %>">
                        <img src="/../Content/Images/icon_newpost.gif" />
                        Chỉnh sửa danh mục </a>
                </div>
            </div>
            <div class="private_write_right">
                <div class="private_bt_newspost">
                    <a href="<%=Url.Action("CreateProduct", "Product" , new { uid = ViewData["MemId"]}) %>">
                        <img src="/../Content/Images/icon_newpost.gif" />
                        Đăng tải sản phẩm </a>
                </div>
            </div>
            <% }
               }%>
            <%--<div class="private_write_right">
                <div class="private_bt_newspost">
                    <a href="<%= Url.Action("List","Product", new { uid = ViewData["MemId"], isEditMode = true}) %>">
                        <img src="/../Content/Images/icon_newpost.gif" />
                        Chỉnh sửa danh mục </a>
                </div>
            </div>
            <div class="private_write_right">
                <div class="private_bt_newspost">
                    <a href="<%=Url.Action("Index", "Product" , new { uid = ViewData["MemId"]}) %>">
                        <img src="/../Content/Images/icon_newpost.gif" />
                        Đăng tải sản phẩm </a>
                </div>
            </div>--%>
        </div>
        <div class="private_comment_top">
            <%--<div class="private_menu_list_product">
                <ul>
                    <li><a href="#">Áo sơ mi</a></li>
                    <li><a href="#">Váy</a></li>
                    <li><a href="#">Vest</a></li>
                    <li><a href="#">Quần</a></li>
                </ul>
            </div>--%>
            <% 
                if (ViewData["Mode"] == "Editing")
                {
                    if (ViewData["ListCates"] != null)
                    {
                        //Response.Write("<form action=" + Url.RouteUrl("PrivateDefaultRoute1", new { uid = ViewData["MemId"], isEditMode = ViewData["isEditMode"] }) + " method='post' enctype='multipart/form-data'>");
                        Response.Write("<form action=" + Url.Action("updateCate", "Product") + " method='post' enctype='multipart/form-data'>");
                        Response.Write("<table>");
                        int rowPerCol = 3;
                        int count = 1;
                        for (int j = 1; j <= 12; j++)
                        {
                            if (count == 1)
                                Response.Write("<tr><td>");
                            Response.Write(Html.DropDownList("drop_" + j, (SelectList)ViewData["ListCates"], new { style = "width:165px" }));
                            if (j % rowPerCol == 0)
                            {
                                Response.Write("</td></tr>");
                                count = 0;
                            }
                            count++;
                        }
                        Response.Write("<tr><td><input type='submit' id='submit' value='Hoàn tất' class='private_bt_submit_news' style='width:90px;'/></td></tr>");
                        Response.Write("</table></form>");

                    }

                    else
                    {
                        Response.Write("<div class='private_menu_list_product'> Không load được dữ liệu</div>");
                    }
                }
                else ViewData["Mode"] = "Showing";
                {
                    int uid = ViewData["MemId"] == null ? -1 : (int)ViewData["MemId"];
                    if (ViewData["ListLinks"] != null)
                    {
                        List<Category> list = (List<Category>)ViewData["ListLinks"];
                        int rowPerCol = 4;
                        int count = 1;
                        for (int j = 1; j <= list.Count; j++)
                        {
                            if (count == 1)
                            {
                                Response.Write("<div class='private_menu_list_product'><ul>");
                            }
                            Response.Write(string.Format("<li> <a href='{0}?cateId={2}'>{1}</a>", Url.RouteUrl("PrivateProductRoute", new { uid = uid, isEditMode = ViewData["isEditMode"] }), list[j - 1].CateName, list[j - 1].CateId) + "</li>");
                            if (j % rowPerCol == 0 && j != 0)
                            {
                                Response.Write("</ul></div>");
                                count = 0;
                            }
                            count++;
                            if (j == list.Count)
                            {
                                if (j < 12)
                                    Response.Write("</ul></div>");
                            }
                        }

                    }
                }
            %>
            <div class="clear">
            </div>
        </div>
        <hr class="private_color_hr" />
        <%
            if (ViewData["ListNewsProduct"] != null)
            {
                int i;
                NewsProductHelper.FetchProductResult lstNews = (NewsProductHelper.FetchProductResult)ViewData["ListNewsProduct"];

                if (lstNews.products.Count > 0)
                {
                    foreach (var item in lstNews.products)
                    {
                        WebHoiChoMuaBan.Controllers.Helpers.NewsProductThumbHelper proThumbHelper = new WebHoiChoMuaBan.Controllers.Helpers.NewsProductThumbHelper();
                        NewsProductThumb newsThumb = proThumbHelper.getProductMainThumbById(item.NProId) == null ? null : proThumbHelper.getProductMainThumbById(item.NProId);
                        Response.Write("<div class='private_thumb_listpr'>");
                        Response.Write("<div class='private_img_post_bt'>");
                        if (newsThumb != null)
                        {
                            Response.Write("<img src='/../Content/Images/Upload/" + newsThumb.NProThumbName + "' class='private_img_post' width='140px' height='100px'/></div>");
                            //Response.Write("<img src='/../Content/Images/no-image.gif' class='private_img_post' width='140px' height='100px'/></div>");
                        }
                        else
                            Response.Write("<img src='/../Content/Images/no-image.gif' class='private_img_post' width='140px' height='100px'/></div>");
                        Response.Write("<div class='private_post_text'>");
                        Response.Write("<a href='/Product/Details?id=" + item.NProId + "&uid=" + item.MemId + "'><p class='private_text_title'>" + item.NProTitle + "</p></a>");
                        //Response.Write("<p>" + item.NProIntro);
                        Response.Write("<br /><strong>Giá bán: </strong>&nbsp;<span class='private_price'>" + String.Format("{0:0,0}", item.NProPrice) + " " + item.NProPriceUnit + "</span></p><br />");
                        Response.Write("<div class='private_listpr_active'>");
                        Response.Write("<p class='private_timer'>(Hcm: 22/10/2011)&nbsp;</p>");
                        if (Session["MemId"] != null && int.Parse(Session["MemId"] + "") == hMem.Member.MemId)
                        {
                            Response.Write("<div class='private_upload_newshot'>");

                            Response.Write("<a href='javacript:void(0)' onclick = 'return ShowOrHide_PostingHotNews(\"show\"," + item.NProId + ")' > <img src='/../Content/Images/upnewshot.gif' alt='' /></a></div>");
                        }
                        Response.Write("<div id='LikeField_" + item.NProId + "'>Thích: Có " + item.NProLike + " người thích </div>");
                        Response.Write("</div><br /");
                        Response.Write("<span><img src='/../Content/Images/turnview.gif'>&nbsp;&nbsp;Lượt xem: 250</span> <span> ");
                        if (Session["MemId"] != null && int.Parse(Session["MemId"] + "") != hMem.Member.MemId)
                        {
                            Response.Write("<a href='#noibat' class='hoicho_bt_action' onclick='LikeCLick(" + item.NProId + ")' id='LikeButton' data-url='" + item.NProId + "'>");
                            Response.Write("<img class='hoicho_bt_action_image ' style='cursor: pointer' align='middle' src='/../Content/Images/like_bt.gif' />Thích</a>");
                            Response.Write("<img src='/../Content/Images/comments_bt.gif' onclick='RegisterReplyButtonMemNews(" + item.NProId + ")' >&nbsp;&nbsp;Bình luận</span>");
                        }
                        else
                        {
                            Response.Write("Đăng nhập để like và bình luận");
                        }
                        Response.Write("  <a class='a2a_dd' href='http://www.addtoany.com/share_save?linkurl=hoichomuaban.com&amp;linkname=Hoi%20Cho%20Mua%20Ban'>");
                        Response.Write(" Share</a> <span class='a2a_divider'></span><a class='a2a_button_facebook'></a>");
                        Response.Write(" <a class='a2a_button_twitter'></a><a class='a2a_button_google_bookmarks'></a><a class='a2a_button_digg'>");
                        Response.Write("   </a> ");
        %>
        <form action="<%=Url.Action("AddComment", "NewsProduct") %>" id="formReplyNews_<%=item.NProId %>"
        method="post" class="private_content_comment hidden">
        <input type="button" value="đóng" style="margin-left: 400px" class="btnReplyClose_<%=item.NProId %>"
            onclick="CloseRegisterReplyButton(<%=item.NProId %>)" />
        <input type="hidden" value="<%=item.NProId %>" name="newsId" id="newsId" />
        <div class="private_menu_topmenu">
            <textarea class="input_full" rows="5" cols="45" id="Textarea2" name="txtComment"></textarea>
        </div>
        <div class="private_post_text">
            <div class="private_button_left">
                <span class="private_font_bold">Chọn icon: </span>
                <% ChatHelper chat = new ChatHelper();
                   List<ChatEmotionDetail> icons = chat.getEmotionPath();
                   foreach (ChatEmotionDetail icon in icons)
                   {
                       Response.Write("<img align='middle' onclick='MemchatIconClick(this)' src='" + icon.path + "' id='" + icon.notation + "' width='40px' height='40px' />");

                   }
                %>
                <script type="text/javascript">
                    function MemchatIconClick(obj) {
                        $this = document.getElementById("txtComment");
                        $this.value += obj.id;
                    }
                    function RegisterReplyButtonMemNews(comid) {
                        var formReply = document.getElementById("formReplyNews_" + comid);
                        $('#formReplyNews_' + comid).show();
                    }

                    function CloseRegisterReplyButton(e) {
                        $('#formReplyNews_' + e).hide();
                    }
                </script>
            </div>
            <div class="private_write_right">
                <input type="submit" style="#width: 60px;" id="Submit3" value="Gửi" class="private_bt_submit_news_disable" />
            </div>
        </div>
        </form>
    </div>
    </div>
    <%
                        
}
                } 
                            
    %>
    <script type="text/javascript">
        function LikeCLick(obj) {
            var sid = $('#LikeButton').data("url");
            var sid = obj;
            $.ajax({
                type: "POST",
                url: "/NewsProduct/Like",
                data: "proId=" + sid,
                success: function (result) {

                    if (result == "null") {
                        alert("Đăng nhập để thích");
                    }
                    else {
                        if (result == "duplicated")
                            alert("Bạn đã thích rồi");
                        else {
                            var ff = document.getElementById("LikeField_" + sid);
                            ff.innerHTML = "Thích: Có " + result + " người thích";

                        }
                    }
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }
    </script>
    <script type="text/javascript">
        function hasClass(el, name) {
            return new RegExp('(\\s|^)' + name + '(\\s|$)').test(el.className);
        }
        function addClass(el, name) {
            if (!hasClass(el, name)) { el.className += (el.className ? ' ' : '') + name; }
        }
        function removeClass(el, name) {
            if (hasClass(el, name)) {
                el.className = el.className.replace(new RegExp('(\\s|^)' + name + '(\\s|$)'), ' ').replace(/^\s+|\s+$/g, '');
            }
        }
        function RegisterReplyButtonMem(comid) {
            var formReply = document.getElementById("formReply_" + comid);
            removeClass(formReply, "hidden");
        }
        //        function RegisterReplyButtonMemNews(comid) {
        //            var formReply = document.getElementById("formReplyNews_" + comid);
        //            removeClass(formReply, "hidden");
        //        }
    </script>
    <center>
        <div class="private_breakpage">
            <%
                int p;
                if (Request.QueryString["p"] == null && !int.TryParse(Request.QueryString["p"], out p))
                {
                    p = 1;
                }
                else p = int.Parse(Request.QueryString["p"]);
            %>
            <% if (p > 1)
               { %><a href='<%=string.Format("{0}?p={1}#noibat'",
                                                       Url.RouteUrl("PrivateDefaultRoute1", new { uid = ViewData["MemId"], isEditMode = ViewData["isEditMode"] }),
                                                        p-1) %>'><img src="/../Content/Images/arrow_breakpage_left.gif" alt="">&nbsp;Trang
                   trước</a>
            <% } %>
            <%
                if (p > 3)
                    Response.Write(string.Format("<a href='{0}?p={1}#noibat'{2}>{3}</a> ",
                                                    Url.RouteUrl("PrivateDefaultRoute1", new { uid = ViewData["MemId"], isEditMode = ViewData["isEditMode"] }),
                                                    1,
                                                    string.Empty,
                                                     1));
                if (p > 4)
                    Response.Write("...");
                int total = lstNews.totalPages;
                int from = (p - 2 < 1 ? 1 : p - 2);
                int to = (p + 2 >= total ? total : p + 2);
                for (i = from; i <= to; i++)
                    Response.Write(string.Format("<a href='{0}?p={1}#noibat'{2}>{3}</a> ",
                        //Url.Action("List", "Product",new { uid = ViewData["MemId"],isEditMode =  Session["isEditMode"]}),
                                                    Url.RouteUrl("PrivateDefaultRoute1", new { uid = ViewData["MemId"], isEditMode = ViewData["isEditMode"] }),
                                                    i,
                                                    (i == p ? "class='menu_select'" : string.Empty),
                                                     i));
                if (p <= total - 4)
                    Response.Write("...");
                if (p <= total - 3)
                    Response.Write(string.Format("<a href='{0}?p={1}#noibat'{2}>{3}</a> ",
                                                    Url.RouteUrl("PrivateDefaultRoute1", new { uid = ViewData["MemId"], isEditMode = ViewData["isEditMode"] }),
                                                    total,
                                                    string.Empty,
                                                    total));
            %>
            <% if (p < lstNews.totalPages)
               { %><a href='<%=string.Format("{0}?p={1}#noibat'",
                                                      Url.RouteUrl("PrivateDefaultRoute1", new { uid = ViewData["MemId"], isEditMode = ViewData["isEditMode"] }),
                                                        p+1) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif" alt=""></a>
            <% }
            }%>
        </div>
    </center>
    </div>
    <!-- Form chi tiết về việc đăng tin -->
    <div class="private_info_product hidden">
        <form action="<%= Url.Action("UpHotnews","Product") %>" id="myForm" method="post"
        enctype="multipart/form-data">
        <input type="input" name="txtId" id="UpTinHotId" value="" />
        <div class="private_post_product_popuptop">
            <p class="private_text_record">
                Số điểm của bạn còn: 150</p>
            <div class="private_view_all" style="margin-top: 0">
                <div class="private_img_footer">
                    <a href="javascript:void(0)" onclick="ShowOrHide_PostingHotNews('hide')">Đóng cửa sổ
                        <img src="/../Content/Images/delete_bt.gif" alt=""></a></div>
            </div>
        </div>
        <div class="private_info_location_news">
            <table border="0" width="100%">
                <tr>
                    <td colspan="4" class="private_font_bold">
                        Chọn vị trí đăng tin
                    </td>
                </tr>
                <tr>
                    <td width="23%">
                        <p>
                            Trang chủ</p>
                        <input type="text" onblur="CalcScore(this,<%=hMem.Member.MemUpPoint %>)" name="txtHotTrangChu"
                            id="txtHotTrangChu" class="input_full" />
                    </td>
                    <td width="29%">
                        <p>
                            Trang danh mục chuyên đề</p>
                        <input type="text" onblur="CalcScore(this,<%=hMem.Member.MemUpPoint %>))" name="txtHotChuyenDe"
                            id="txtHotChuyenDe" class="input_full" />
                    </td>
                    <td width="28%">
                        <p>
                            Trang chuyên đề chi tiết</p>
                        <input type="text" onblur="CalcScore(this,<%=hMem.Member.MemUpPoint %>))" name="txtHotChiTiet"
                            id="txtHotChiTiet" class="input_full" />
                    </td>
                    <td width="20%">
                        <p>
                            Tổng điểm phải trả</p>
                        <input type="text" name="txtHotScore" id="txtHotScore" class="input_full" />
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        Thời gian lặp lại:
                        <input type="checkbox" name="checkbox1" id="checkbox4" />1h
                        <label for="checkbox4">
                            <input type="checkbox" name="checkbox6" id="checkbox" />
                            6h
                            <input type="checkbox" name="checkbox12" id="checkbox2" />
                            12h
                            <input type="checkbox" name="checkbox24" id="checkbox3" />
                            24h
                        </label>
                    </td>
                    <td align="right">
                        <div class="private_margin_topright private_write_right">
                            <input type="submit" class="private_bt_submit_news" value="Đăng quảng cáo" id="">
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="private_img_footer">
            <div class="private_bt_member_left">
                <p class="private_font_bold">
                    Chi phí cho mỗi lần xuất hiện:</p>
                <p>
                    Trang chủ 6 điểm, Trang chuyên đề 4 điểm, Trang chuyên đề chi tiết 2 điểm</p>
            </div>
            <div class="private_view_all">
                <div class="private_margin_topright private_write_right">
                    <input type="submit" value="Mua thêm điểm đăng tin" class="private_bt_submit_news_disable"
                        id="">
                </div>
            </div>
        </div>
        <div id="submitForm">
            <input type="button" onclick='missPoint()' value="Xác nhận" />
        </div>
        </form>
    </div>
    <script type="text/javascript">
        function missPoint() {
            alert("không  đủ point để thực hiện tác vụ này");
        }
        function CalcScore(obj, sco) {
            var scoretc;
            var hotscoretc = document.getElementById("txtHotTrangChu");

            if (hotscoretc.value.length == 0) {
                scoretc = 0;
            }
            else {
                scoretc = parseInt(hotscoretc.value) * 6;
            }

            var scorecd;
            var hotscorecd = document.getElementById("txtHotChuyenDe");

            if (hotscorecd.value.length == 0) {
                scorecd = 0;
            }
            else {
                scorecd = parseInt(hotscorecd.value) * 4;
            }

            var scoredt;
            var hotscoredt = document.getElementById("txtHotChiTiet");

            if (hotscoredt.value.length == 0) {
                scoredt = 0;
            }
            else {
                scoredt = parseInt(hotscoredt.value) * 2;
            }


            var total = scoretc + scoredt + scorecd;

            document.getElementById("txtHotScore").value = total;
            var ff = document.getElementById("submitForm");
            if (total > parseInt(sco)) {
                ff.innerHTML = "<input type='button' onclick='missPoint()' value='Xác nhận' />";
            }
            else {
                ff.innerHTML = "<input type='submit' value='Xác nhận' id='txtSubmit' />";
            }
        }

      
    </script>

</asp:Content>
